﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;

/// <summary>
/// Summary description for BasePage
/// </summary>
public class BasePage : Page
{
    #region JS事件

    /// <summary>
    /// 关闭页面
    /// </summary>
    protected void CloseWindow()
    {
        //this.ClientScript.RegisterStartupScript(this.GetType(), "closewindow", "window.close();", true);
        ScriptManager.RegisterStartupScript(this, GetType(), "closewindow", "window.close();", true);
    }

    /// <summary>
    /// 关闭页面
    /// </summary>
    protected void ReturnAndClose(string returnValue)
    {
        //this.ClientScript.RegisterClientScriptBlock(this.GetType(), "closewindow", returnValue + "window.close();", true);
        ScriptManager.RegisterStartupScript(this, GetType(), "closewindow", returnValue + "window.close();", true);
    }

    /// <summary>
    /// 提示关闭返回
    /// </summary>
    protected void AlterCloseReturn(string msg, string returnValue)
    {
        ScriptManager.RegisterStartupScript(this, GetType(), "closewindow",
                                            "alert('" + msg + "');" + returnValue + "window.close();", true);
    }

    /// <summary>
    /// 弹出提示信息
    /// </summary>
    /// <param name="msg"></param>
    protected void AlertMsg(string msg)
    {
        //this.ClientScript.RegisterStartupScript(this.GetType(), "alertmsg", "alert('" + msg + "');", true);
        msg = msg.Replace("'", "\'");
        msg = msg.Replace(Environment.NewLine, "\\n");
        ScriptManager.RegisterStartupScript(this, GetType(), "alertmsg", "alert(\"" + msg + "\");", true);
    }

    /// <summary>
    /// 弹出提示并跳转页面
    /// </summary>
    /// <param name="msg"></param>
    /// <param name="url"></param>
    protected void AlterAndRedirect(string msg, string url)
    {
        //this.ClientScript.RegisterClientScriptBlock(this.GetType(), "alertmsg", "alert('" + msg + "');location.href='" + url + "';", true);
        ScriptManager.RegisterStartupScript(this, GetType(), "alertmsg",
                                            "alert('" + msg + "');location.href='" + url + "';", true);
    }

    /// <summary>
    /// 注册方法
    /// </summary>
    protected void RegisterMethod(string methodName)
    {
        //this.ClientScript.RegisterClientScriptBlock(this.GetType(), "RegisMethod", methodName, true);
        ScriptManager.RegisterStartupScript(this, GetType(), "RegisMethod", methodName, true);
    }

    #endregion
}